import Mock from 'mockjs'
import type { Request } from 'express'
export default [
  // 红娘列表数据
  {
    method: 'get',
    url: '/api/lady',
    response: (req: Request) => {
      // 页码
      let page = req.query.page ? Number(req.query.page) : 1
      // 每页要显示的记录条数，默认为10条
      let size = req.query.size ? Number(req.query.size) : 10
      let total = 65
      // 计算总页数
      let totalPages = Math.ceil(total / size);

      // 计算实际每页要显示的记录数
      let pageSize = page < totalPages ? size : total - size * (totalPages - 1);
      const userData = Mock.mock({
        [`users|${pageSize}`]: [
          {
            'id|+1': (page - 1) * size + 1,
            username: '@string("lower", 5)',
            'sex|1': ['1', '2'],
            'age|1-200': 25,
            region: ['安徽', '芜湖'],
            avatar: "@image('50x100', '#50B347', '#FFF', 'Mock')",
            realname: '@cname()',
            cdate: '@date("yyyy-MM-dd")',
            phone: 1231445566,
            wechat: 13245

          }
        ]
      })
      return {
        code: 0,
        msg: 'ok',
        data: {
          ...userData,
          total
        }
      }
    }
  }
,
   // 检查用户名是否存在
   {
    method: 'post',
    url: '/api/ladycheckUsername',
    response: (req: Request) => {
      // 获取到post数据
      // console.log(req.body)
      let data = 0
      const username = req.body.username
      if (username === 'admin') data = 1
      return {
        code: 0,
        msg: 'ok',
        // 0不存在，1存在
        data
      }
    }
  },
// 添加红娘用户数据到表格中显示
{
  method: 'post',
  url: '/api/lady',
  response: (req: Request) => {
    return {
      code: 0,
      msg: 'ok',
      data: {
        id: Date.now(),
        ...req.body
      }
    }
  }
},
 // 根据用户id返回对应用户对象
 {
  method: 'get',
  url: '/api/lady/:id',
  response: (req: Request) => {
    return {
      code: 0,
      msg: 'ok',
      data: {
        id: req.query.id ? +req.query.id : 0,
        username: '333',
        sex: '2',
        age: 104,
        region: ['北京', '昌平'],
        avatar: 'http://dummyimage.com/50x100/50B347/FFF&text=Mock',
        realname: '张三',
        cdate: '1991-03-17'
      }
    }
  }
},
// 根据用户id返回对应用户数据
{
  method: 'post',
  url: '/api/lady/:id',
  response: (req: Request) => {
    return {
      code: 0,
      msg: 'ok',
      data: 1
    }
  }
}

]